package untiring07_HelloJDBC;

import java.util.List;
import java.util.Scanner;

public class J03_MemberService implements J03_IMemberService {

	// 회원 가입/조회/수정/삭제 처리를 위해
	// MemberDAO 클래스의 객체를 미리 생성
	private J03_MemberDAO mdao = new J03_MemberDAO();

	@Override
	public void creatMember() {
		System.out.println("1.회원가입");

		Scanner sc = new Scanner(System.in);
		J03_MemberVO m = new J03_MemberVO();

		System.out.println("아이디를 입력하세요");
		m.setUserid(sc.next());
		System.out.println("비밀번호를 입력하세요");
		m.setPasswd(sc.next());
		System.out.println("이름을 입력하세요");
		m.setName(sc.next());
		System.out.println("이메일을 입력하세요");
		m.setEmail(sc.next());
		// 입력받은 데이터들을 member
		if (mdao.insertMember(m))
			System.out.println("회원가입성공!");
		else
			System.out.println("회원가입실패");

	}

	@Override
	public void readMember() {
		// select 문을 이용해서 member 테이블의 모든
		// 레코드를 가져와서 콘솔에 출력 
		List<J03_MemberVO >result = mdao.selectMember();
		for(int i = 0; i<result.size();++i){
			J03_MemberVO v = result.get(i);
			System.out.println(v.getMno());
		}
		
		for(J03_MemberVO m:mdao.selectMember()){
			System.out.print(m.getMno());
			System.out.print("/");
			System.out.print(m.getUserid());
			System.out.print("/");
			System.out.print(m.getPasswd());
			System.out.print("/");
			System.out.print(m.getName());
			System.out.print("/");
			System.out.print(m.getEmail());
			System.out.print("/");
			System.out.println(m.getRegdate());
			
		}
		
	}

	@Override
	public void modifyMember() {
		Scanner sc = new Scanner(System.in);
		J03_MemberVO mvo = new J03_MemberVO();
		readMember();
		System.out.println("수정할 회원 번호를 입력하세요");
		mvo.setMno(sc.next());
		System.out.println("새로운 비밀번호를 입력하세요");
		mvo.setPasswd(sc.next());
		System.out.println("새로운 이름을 입력하세요");
		mvo.setName(sc.next());
		System.out.println("새로운 이메일을 입력하세요");
		mvo.setEmail(sc.next());
		System.out.println("");
		if(mdao.updateMember(mvo))
			System.out.println("회원정보수정 성공");
		else
			System.out.println("회원정보수정 실패");
	}

	@Override
	public void removeMember() {
		Scanner sc = new Scanner(System.in);
		J03_MemberVO mvo = new J03_MemberVO();
		readMember(); // 전체회원 출력
		System.out.println("삭제할 회원의 번호를 입력하세요");
		mvo.setMno(sc.next());
		if(mdao.deleteMember(mvo))
			System.out.println("회원정보삭제 성공");
		else
			System.out.println("회원정보삭제 실패");
	}

}
